package main

import (
	"fmt"
	"time"
)

var deposits = make(chan int) // send amount to deposit

var balances = make(chan int) // receive balance

func Deposit(amount int) { deposits <- amount }

func Balance() int { return <-balances }

func teller() {
	var balance int
	for {
		select {
		case amount := <-deposits:
			balance += amount
		case balances <- balance:
		}
	}
}

func init() {
	go teller()
}

func main() {
	go Deposit(100)
	go Deposit(100)
	go Deposit(100)

	go fmt.Println(Balance())

	time.Sleep(2 * time.Second)
}
